const getwxphone = require("../../../utils/getwxphone.js")
const api = require("../../../utils/api.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.redirectTo({
      url: '../agreement/agreement',
    })
  },
  getPhoneNumber(e) {
    var _ = this;
    var flag = this.data.flag;
    const info = {
      area: wx.getStorageSync('area'),
      agent: wx.getStorageSync('agent'),
      page: wx.getStorageSync('page'),
      activeId: 46
    }

    if (flag) {
      getwxphone(e.detail.code, 51134, 'biaodan', info)
        .then(res => {
          console.log(res);
          wx.request({
            url: 'https://zg99.offcn.com/index/wechat/getsesionkey?actid=51134',
            method: 'get',
            data: {
              code: this.data.code
            },
            success(res) {
              console.log(res)
              if (res.data.openid) {
                wx.request({
                  url: 'https://zg99.offcn.com/index/biaodan/updateuser?actid=51134',
                  method: 'get',
                  data: {
                    oid: res.data.openid,
                    sstimes: Date.parse(new Date()),
                    phone: wx.getStorageSync('51134phone')
                  },
                  success(res) {

                    wx.showModal({
                      title: '提示',
                      content: '是否需要推送成绩查询提醒',
                      success(res) {
                        if (res.confirm) {
                         
                          wx.requestSubscribeMessage({
                            tmplIds: ['DGG6d8xTrFl13CokIVtf-iT33qG3kzn_mX3MZjuYM1M'], //笔试时间
                            success(res) {
                              console.log(res);
                              _.setData({
                                fixed: 1
                              })
                            },
                            fail(res) {
                              console.log(res);
                            }
                          })
                        } else if (res.cancel) {
                          console.log('用户点击取消')
                        }
                      }
                    })

                  }
                })
              } else {
                api.showToast('已经成功预约！')
              }

            }
          })
        })
        .catch(err => {
          console.log(err);
          
        })
    } else {
      api.showToastNone('请先同意隐私保护协议！')
    }
  },
  close() {
    this.setData({
      fixed: !1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    api.load(options)
    wx.login({
      success: (res) => {
        var code = res.code;
        this.setData({
          code
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})